package com.edu.atams.controller;


import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.edu.atams.common.lang.Result;
import com.edu.atams.entity.SysUser;
import org.springframework.web.bind.annotation.*;


/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author czj666
 * @since 2021-10-09
 */
@RestController
@RequestMapping("/sys/user")
public class SysUserController extends BaseController {

    @GetMapping("/list")
    public Result list(String username){
        Page<SysUser> page = sysUserService.page(getPage(), new QueryWrapper<SysUser>().like(StrUtil.isNotBlank(username), "username", username));
        return Result.succ(page);
    }

    @PostMapping("/repass/{id}")
    public Result repass(@PathVariable("id") Integer id){
        SysUser sysUser = sysUserService.getById(id);
        String password = bCryptPasswordEncoder.encode("123456");
        sysUser.setPassword(password);
        sysUserService.updateById(sysUser);
        return Result.succ("");
    }

    @PostMapping("/reVX/{id}")
    public Result reVX(@PathVariable("id") Integer id){
        SysUser sysUser = sysUserService.getById(id);
        sysUser.setOpenid("");
        sysUserService.updateById(sysUser);
        return Result.succ("");
    }

}
